package array;

import java.util.Arrays;
import java.util.Stack;

public class L26 {
    public static int removeDuplicates(int[] nums) {
        Stack<Integer> stack = new Stack<>();
        stack.push(nums[0]);
        for (int i=1;i<nums.length;i++){
            if (nums[i]!=stack.peek()){
                stack.push(nums[i]);
            }
        }
        int sub=stack.size();

        while (stack.size()!=0){
            int i=stack.size()-1;
            Integer pop = stack.pop();
            nums[i--]=pop;
        }
        nums = Arrays.copyOf(nums, sub);

        return nums.length;


    }
    public static void main(String[] args) {
        int arr[]={0,0,1,1,1,2,2,3,3,4};
        int i = removeDuplicates(arr);
        System.out.println(i);


    }
}
